﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FastReport;
using MINERP.BLL.Statistics;

namespace MINERP.Statistics.Forms
{
    public partial class FrmProductInfomation : Form
    {
        public FrmProductInfomation()
        {
            InitializeComponent();
        }
        private static FrmProductInfomation _instance;

        public static FrmProductInfomation GetInstance
        {
            get
            {
                if (_instance == null || _instance.Disposing)
                {
                    _instance = new FrmProductInfomation();
                }

                return _instance;
            }
        }
        private void buttonOk_Click(object sender, EventArgs e)
        {
            ProductInfomationBLL _bll=new ProductInfomationBLL();

            DateTime startTime = dtStart.DateTime.Date;
            DateTime endTime = dtEnd.DateTime.AddDays(1).Date.AddSeconds(-1);
            
            try
            {

                this.Cursor = Cursors.WaitCursor;
                DataSet set = _bll.GetProductInfomation(startTime,endTime);
                set.WriteXml(@"C:\windows\xmlData\产品生产信息.xml", XmlWriteMode.WriteSchema);
                Report report = new Report();
                report.Load(Application.StartupPath + "\\Report\\产品生产信息.frx");
                report.Preview = previewControl1;
                report.SetParameterValue("ParaStartTime", startTime.ToString());
                report.SetParameterValue("ParaEndTime",endTime.ToString());
                previewControl1.Refresh();
                previewControl1.Show();
                report.Show();
            }
            catch (Exception)
            {
                MessageBox.Show("读取数据失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void FrmProductInfomation_FormClosing(object sender, FormClosingEventArgs e)
        {
            _instance = null;
        }

        private void FrmProductInfomation_Load(object sender, EventArgs e)
        {
            dtStart.DateTime = DateTime.Now;
            dtEnd.DateTime = DateTime.Now;
        }
    }
}
